package com.zh.media.utils.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class BarcodeView extends View {

    private String barcodeData;

    public BarcodeView(Context context, AttributeSet attrs) {
        super(context, attrs);
        barcodeData = "123456789012"; // 条形码数据
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width = getWidth();
        int height = getHeight();
        int barcodeWidth = width / barcodeData.length(); // 条形码单元宽度
        int barcodeHeight = height; // 条形码高度

        for (int i = 0; i < barcodeData.length(); i++) {
            Paint paint = new Paint();
            canvas.drawRect(i * barcodeWidth, 0, (i + 1) * barcodeWidth, barcodeHeight, paint);
        }
    }
}
